package com.iwomy.envpro.platform.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iwomy.envpro.platform.entity.BasicSmsConfigEntity;
import com.iwomy.envpro.platform.mapper.BasicSmsConfigMapper;
import com.iwomy.envpro.platform.service.BasicSmsConfigService;
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
import org.dromara.sms4j.aliyun.config.AlibabaFactory;
import org.dromara.sms4j.aliyun.service.AlibabaSmsImpl;
import org.dromara.sms4j.comm.constant.SupplierConstant;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.dromara.sms4j.provider.service.AbstractSmsBlend;
import org.dromara.sms4j.tencent.config.TencentConfig;
import org.dromara.sms4j.tencent.config.TencentFactory;
import org.springframework.stereotype.Service;

/**
 * 基础信息-短信配置
 *
 * @author pig
 * @date 2023-09-23 15:46:27
 */
@Service
public class BasicSmsConfigServiceImpl extends ServiceImpl<BasicSmsConfigMapper, BasicSmsConfigEntity> implements BasicSmsConfigService {
	@Override
	public AbstractSmsBlend getSmsBlend(BasicSmsConfigEntity smsConfig ) {

		BaseConfig baseConfig = null;

		switch (smsConfig.getSupplier()) {
			case SupplierConstant
					.ALIBABA:
				baseConfig = new AlibabaConfig();
				break;
			case SupplierConstant.TENCENT:
				baseConfig = new TencentConfig();
				break;
			default:
		}
		baseConfig.setAccessKeyId(smsConfig.getAccessKeyId());
		baseConfig.setAccessKeySecret(smsConfig.getAccessKeySecret());
		baseConfig.setSdkAppId(smsConfig.getSdkAppId());
		baseConfig.setTemplateId(smsConfig.getTemplateCode());
		baseConfig.setSignature(smsConfig.getSignatureName());
		baseConfig.setConfigId(smsConfig.getId().toString());
		//此处仅为示例，实际环境中，数据可以来自任意位置，

		switch (smsConfig.getSupplier()) {
			case SupplierConstant
					.ALIBABA:
				return AlibabaFactory.instance().createSms((AlibabaConfig) baseConfig);
			case SupplierConstant.TENCENT:
				return TencentFactory.instance().createSms((TencentConfig) baseConfig);
			default:
		}

		return null;
	}
}